package org.jash.demo2205

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.databinding.DataBindingUtil
import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.alibaba.android.arouter.utils.TextUtils
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jash.demo2205.databinding.ActivityMainBinding
import org.jash.demo2205.entity.User
import org.jash.demo2205.shop.ShopActivity
import org.jash.demo2205.utils.SPUtils

class MainActivity : AppCompatActivity() {
    val binding:ActivityMainBinding by lazy { DataBindingUtil.setContentView(this, R.layout.activity_main) }
    val count:ObservableInt by lazy { ObservableInt(5) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.count = count
        lifecycleScope.launch {
            for (i in count.get() downTo 0) {
                count.set(i)
                delay(1000)
            }
            ARouter.getInstance().build(if (TextUtils.isEmpty(SPUtils.instance.getString("token", ""))) "/shop/login" else "/shop/shop").navigation()
            finish()
        }
    }
}